;; ido
(global-set-key [(control b)] 'ido-switch-buffer)

;; editing
(global-set-key [(control z)] 'undo)                    ; undo only in graphic mode
(global-set-key [(meta g)] 'goto-line)                  ; goto line #
(global-set-key (kbd "M-k") 'kill-whole-line)		; kill whole line
(global-set-key (kbd "C-d") 'duplicate-line)		; duplicate line

;; isearch
(global-set-key [(control f)] 'isearch-forward-regexp)  ; search regexp
(global-set-key [(control r)] 'query-replace-regexp)    ; replace regexp
(define-key
  isearch-mode-map
  [(control n)]
  'isearch-repeat-forward)                              ; next occurence
(define-key
  isearch-mode-map
  [(control p)]
  'isearch-repeat-backward)                             ; previous occurence
(define-key
  isearch-mode-map
  [(control z)]
  'isearch-cancel)                                      ; quit and go back to start point
(define-key
  isearch-mode-map
  [(control f)]
  'isearch-exit)                                        ; abort
(define-key
  isearch-mode-map
  [(control r)]
  'isearch-query-replace)                               ; switch to replace mode
(define-key
  isearch-mode-map
  [S-insert]
  'isearch-yank-kill)                                   ; paste
(define-key
  isearch-mode-map
  [(control e)]
  'isearch-toggle-regexp)                               ; toggle regexp
(define-key
  isearch-mode-map
  [(control l)]
  'isearch-yank-line)                                   ; yank line from buffer
(define-key
  isearch-mode-map
  [(control w)]
  'isearch-yank-word)                                   ; yank word from buffer
(define-key
  isearch-mode-map
  [(control c)]
  'isearch-yank-char)                                   ; yank char from buffer

;; buffer
(global-set-key [M-left] 'windmove-left)                ; move to left windnow
(global-set-key [M-right] 'windmove-right)              ; move to right window
(global-set-key [M-up] 'windmove-up)                    ; move to up windnow
(global-set-key [M-down] 'windmove-down)                ; move to down window
(global-set-key [(control tab)] 'other-window)          ; Ctrl-Tab = Next buffer
(global-set-key [C-home] 'beginning-of-buffer)          ; go to the beginning of buffer
(global-set-key [C-end] 'end-of-buffer)                 ; go to the end of buffer
(global-set-key "\M- " 'hippie-expand)		        ; auto completion
(global-set-key [(control o)] 'mark-whole-buffer)       ; select whole buffer
(global-set-key (kbd "C-x n") 'revert-buffer)           ; revert buffer
(when (fboundp 'ibuffer)
  (global-set-key (kbd "C-x C-b") 'ibuffer))            ; ibuffer

;; windows
(global-unset-key [(control s)])
(global-set-key [(control s) (v)] 'split-window-horizontally)
(global-set-key [(control s) (h)] 'split-window-vertically)
(global-set-key [(control s) (d)] 'delete-window)
(global-set-key [(control s) (o)] 'delete-other-windows)

;; c-mode
(require 'switch-file)
(global-set-key [f1] 'switch-cc-to-h)

;; programming
(autoload 'linum-mode "linum" "mode for line numbers" t)
(global-set-key (kbd "<f5>") 'linum-mode)                 ;; line numbers
(global-set-key (kbd "<f6>") 'magit-status)               ;; ...git mode
(global-set-key (kbd "<f7>") 'compile)                     ;; compile

;; c++-mode c-d cmd patch
(defun c++-mode-patch ()
  (local-unset-key (kbd "C-d"))
  )
(add-hook 'c++-mode-hook 'c++-mode-patch)
